/* Copyright (c) 2004-2024 Peigen.info. All rights reserved. */

package info.peigen.hotpot.business.account.core.domain.account.action;

import info.peigen.hotpot.business.account.core.domain.account.Account;
import info.peigen.hotpot.business.account.core.util.CreateAccountUtil;
import info.peigen.hotpot.business.account.facade.enums.AccountType;
import info.peigen.hotpot.business.account.facade.order.create.*;
import info.peigen.hotpot.common.core.enums.Currency;
import info.peigen.hotpot.common.service.base.processor.ProcessorServiceContext;

import static info.peigen.hotpot.business.account.facade.enums.AccountType.*;
import static info.peigen.hotpot.business.router.facade.enums.ChannelCode.Weixin;


/**
 * <b>(AccountDomainAction)</b>
 *
 * @author Peigen
 * @version 1.0.0
 * @since 2021/8/12
 */
public class AccountDomainAction {
    public static Account createCustomerAccount(ProcessorServiceContext serviceContext) {
        CreateCustomerAccountOrder order   = (CreateCustomerAccountOrder) serviceContext.getOrder();
        Account                    account = genAccount(Customer, order.getCustomerId(), order.getCustomerId(), order.getPartnerId(), null);

        serviceContext.setDomain(account);
        return account;
    }

    public static Account createProvisionsAccount(ProcessorServiceContext serviceContext) {
        CreateProvisionsAccountOrder order     = (CreateProvisionsAccountOrder) serviceContext.getOrder();
        String                       accountId = CreateAccountUtil.createProvisionsAccountId();

        Account account = genAccount(Provisions, accountId, accountId, order.getPartnerId(), order.getAliasName());
        serviceContext.setDomain(account);
        return account;
    }

    public static Account createFeeAccount(ProcessorServiceContext serviceContext) {
        CreateFeeAccountOrder order     = (CreateFeeAccountOrder) serviceContext.getOrder();
        String                accountId = CreateAccountUtil.createFeeAccountId();
        Account               account   = genAccount(Fee, accountId, accountId, order.getPartnerId(), order.getAliasName());

        serviceContext.setDomain(account);
        return account;
    }

    public static Account createIntermediateAccount(ProcessorServiceContext serviceContext) {
        CreateIntermediateAccountOrder order     = (CreateIntermediateAccountOrder) serviceContext.getOrder();
        String                         accountId = CreateAccountUtil.createIntermediateAccountId();

        Account account = genAccount(Intermediate, order.getPartnerId(), accountId, order.getPartnerId(), order.getAliasName());
        serviceContext.setDomain(account);
        return account;
    }

    public static Account createPartnerAccount(ProcessorServiceContext serviceContext) {
        CreatePartnerAccountOrder order   = (CreatePartnerAccountOrder) serviceContext.getOrder();
        Account                   account = genAccount(Partner, order.getPartnerId(), order.getPartnerId(), order.getPartnerId(), order.getAliasName());

        serviceContext.setDomain(account);
        return account;
    }

    private static Account genAccount(AccountType accountType, String customerId, String accountId, String partnerId, String aliasName) {
        return Account.builder().accountType(accountType).customerId(customerId).accountId(accountId).partnerId(partnerId)
                .aliasName(aliasName).currency(Currency.CNY).code(Weixin).build();
    }
}